package com.example.demo.service.impl;

import com.example.demo.bean.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("UserService")
public class UserServiceImpl implements UserService {
    @Autowired(required=true)
    @Qualifier("UserMapper")
    private UserMapper userMapper;

    @Override
    public List<User> findAllUser() {
        if(userMapper.findAllUser() == null)
        {
            System.out.println("null");
            return null;
        }
        else
        {

            return userMapper.findAllUser();
        }
    }

    @Override
    public User findUserByUserName(String userName) {
        if(userMapper.findUserByUserName(userName) == null)
            return null;
        else
        {
            return userMapper.findUserByUserName(userName);
        }
    }

    @Override
    public User findUserByUser(User user) {
//        User userTemp = new User();
//        System.out.println(userMapper);
        if(userMapper.findUserByUser(user.getUserNum(), user.getUserPwd()) == null) {
            System.out.println();
            return null;
        }
        else {
            return userMapper.findUserByUser(user.getUserNum(), user.getUserPwd());
        }
    }

    @Override
    public boolean insertUser(User user) {
        return userMapper.insertUser(user.getUserNum(), user.getUserPwd(),user.getMember());
    }

    @Override
    public boolean deleteUserById(String userNum) {
        return userMapper.deleteUser(userNum);
    }
    @Override
    public boolean updateUserPwd(String userName, String userPwd) {
        return userMapper.updatePwd(userName,userPwd);
    }
}
